package com.angel.architecture.services.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.angel.architecture.daos.ConfigurationParameterDAO;
import com.angel.architecture.daos.ErrorMessageDAO;
import com.angel.architecture.persistence.base.PersistentObject;
import com.angel.architecture.persistence.beans.ErrorMessage;
import com.angel.architecture.services.ErrorMessageService;


/**
 *
 * @author William
 *
 */
public class ErrorMessageServiceImpl extends GenericServiceImpl implements ErrorMessageService{

    @Autowired
    private ConfigurationParameterDAO configurationParameterDAO;

    public List<ErrorMessage> findAllByOtherDetails(String details) {
        return (List<ErrorMessage>) this.getErrorMessageDAO().findAllByOtherDetails(details);
    }

    public List<ErrorMessage> findAllBetweenCreationDate(Date beforeCreationDate, Date afterCreationDate) {
        return (List<ErrorMessage>) this.getErrorMessageDAO().findAllBetweenCreationDate(beforeCreationDate, afterCreationDate);
    }

    public PersistentObject create(PersistentObject errorMessage) {
        boolean allowErrorMessage = this.getConfigurationParameterDAO().findAllowLogErrorMessages();
        if(allowErrorMessage){
            return super.create(errorMessage);
        }
        return errorMessage;
    }

    public ErrorMessageDAO getErrorMessageDAO() {
        return (ErrorMessageDAO) this.getGenericDAO();
    }

    public ConfigurationParameterDAO getConfigurationParameterDAO() {
        return configurationParameterDAO;
    }

    public void setConfigurationParameterDAO(ConfigurationParameterDAO configurationParameterDAO) {
        this.configurationParameterDAO = configurationParameterDAO;
    }
}